import Vue from 'vue'
import App from './App'
import request from '@/utils/request'

// 格式化url参数
const qs = {
  stringify(query = {}) {
    return Object.entries(query).reduce(
      (total, [key, value]) => `${total}&${key}=${value}`,
      ''
    )
  }
}

Vue.config.productionTip = false
// 请求工具类挂载
Vue.prototype.$http = request
// 请提示
Vue.prototype.$toast = title => {
  wx.showToast({
    title,
    icon: 'none'
  })
}

Vue.prototype.$router = {
  push({ name, query = {} }) {
    const search = qs.stringify(query)
    const path = `/pages/${name}/main?${search}`
    wx.navigateTo({ url: path })
  },
  replace({ name, query = {} }) {
    const search = qs.stringify(query)
    const path = `/pages/${name}/main?${search}`
    wx.redirectTo({ url: path })
  }
}

App.mpType = 'app'

const app = new Vue(App)
app.$mount()
